package org.skyfree.ghyll.tcard.action;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.graphics.Image;
import org.skyfree.ghyll.tcard.control.ChooseRepoWorkpieceDialog;
import org.skyfree.ghyll.tcard.core.ITProject;

public class ImportWorkpieceMenuItemAction extends AbstractMenuItemAction {

	public ImportWorkpieceMenuItemAction(int style, String text, int Accelerator,
			Image image,TreeViewer treeViewer) {
		super(style, text, Accelerator, image,treeViewer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void execute(Object source) throws Exception 
	{
		ChooseRepoWorkpieceDialog fd = new ChooseRepoWorkpieceDialog(this.treeViewer.getTree().getShell());
		ITProject project = (ITProject) this.item.getData();
		fd.setProject(project);
		if(fd.open()==IDialogConstants.OK_ID)
		{
			project.importWorkpieces(fd.getSelections());
		}
	}

	@Override
	public boolean isEnable() 
	{
		
		Object data = this.item.getData();
		if(data instanceof ITProject)
		{
			ITProject select = (ITProject)data;
			if(select.getStatus()==ITProject.STATUA_CLOSE)return false;
			else return true;
		}
		else return false;
	}

}
